home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / emacs.lha / emacs-19.16 / lisp / metamail.el < prev    next >
Lisp/Scheme  |  1993-06-21  |  4KB  |  120 lines

  1. ;;; Metamail interface for GNU Emacs
  2. ;; Copyright (C) 1993 Masanobu UMEDA
  3.  
  4. ;; Author: Masanobu UMEDA <umerin@mse.kyutech.ac.jp>
  5. ;; Version: $Header: metamail.el,v 1.3 93/06/21 15:37:28 umerin Exp $
  6. ;; Keywords: mail, news, mime, multimedia
  7.  
  8. ;; This file is part of GNU Emacs.
  9.  
  10. ;; GNU Emacs is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License as published by
  12. ;; the Free Software Foundation; either version 2, or (at your option)
  13. ;; any later version.
  14.  
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19.  
  20. ;; You should have received a copy of the GNU General Public License
  21. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  22. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. ;;; Commentary:
  25.  
  26. ;; LCD Archive Entry:
  27. ;; metamail|Masanobu UMEDA|umerin@mse.kyutech.ac.jp|
  28. ;; Metamail interface for GNU Emacs|
  29. ;; $Date: 93/06/21 15:37:28 $|$Revision: 1.3 $|~/misc/metamail.el.Z|
  30.  
  31. ;; Note: Metamail does not have all options which is compatible with
  32. ;; the environment variables.  For that reason, matamail.el have to
  33. ;; hack the environment variables.  In addition, there is no way to
  34. ;; display all header fields without extra informative body messages
  35. ;; which is suppressed by "-q" option.
  36.  
  37. ;; The idea of using metamail to process MIME messages is from
  38. ;; gnus-mime.el by Spike <Spike@world.std.com>.
  39.  
  40. ;;; Code:
  41.  
  42. (defvar metamail-program-name "metamail"
  43.   "*Metamail program name.")
  44.  
  45. (defvar metamail-environment "KEYHEADS='*';export KEYHEADS;"
  46.   "*Environment variables for Metamail.
  47. It must be an emtpy string or a string terminated with ';'.")
  48.  
  49. (defvar metamail-switches '("-m" "emacs" "-x" "-d" "-z")
  50.   "*Switches for Metamail program.
  51. -z is required to remove zap file.")
  52.  
  53. (defun metamail-buffer (&optional buffer)
  54.   "Process current buffer through 'metamail'.
  55. Optional argument BUFFER specifies a buffer to be filled (nil means current)."
  56.   (interactive)
  57.   (metamail-region (point-min) (point-max) buffer))
  58.  
  59. (defun metamail-region (beg end &optional buffer)
  60.   "Process current region through 'metamail'.
  61. Optional argument BUFFER specifies a buffer to be filled (nil means current)."
  62.   (interactive "r")
  63.   (let ((curbuf (current-buffer))
  64.     (buffer-read-only nil)
  65.     (metafile (make-temp-name "/tmp/metamail")))
  66.     (save-excursion
  67.       ;; Gee!  Metamail does not ouput to stdout if input comes from
  68.       ;; stdin.
  69.       (write-region beg end metafile nil 'nomessage)
  70.       (if buffer
  71.       (set-buffer buffer))
  72.       (setq buffer-read-only nil)
  73.       ;; Clear destination buffer.
  74.       (if (eq curbuf (current-buffer))
  75.       (delete-region beg end)
  76.     (delete-region (point-min) (point-max)))
  77.       ;; We have to pass the environment variable KEYHEADS to /bin/sh
  78.       ;; to display all header fields.  Metamail should have an
  79.       ;; optional argument to pass such information directly.
  80.       (apply (function call-process)
  81.          "/bin/sh"
  82.          nil
  83.          t                ;Output to current buffer
  84.          t                ;Force redisplay
  85.          (list "-c"
  86.            ;; Construct environment and the command.
  87.            (concat
  88.             metamail-environment
  89.             metamail-program-name
  90.             " "
  91.             (mapconcat (function identity) metamail-switches " ")
  92.             " "
  93.             metafile
  94.             )))
  95.       )))
  96.  
  97. ;(defun metamail-region (beg end &optional buffer)
  98. ;  "Process current region through 'metamail'.
  99. ;Optional argument BUFFER specifies a buffer to be filled (nil means current)."
  100. ;  (interactive "r")
  101. ;  (let ((curbuf (current-buffer))
  102. ;    (buffer-read-only nil)
  103. ;    (metafile (make-temp-name "/tmp/metamail")))
  104. ;    (save-excursion
  105. ;      (write-region (point-min) (point-max) metafile nil 'nomessage)
  106. ;      (if (eq curbuf
  107. ;          (if buffer (get-buffer buffer) (current-buffer)))
  108. ;      (delete-region (point-min) (point-max)))
  109. ;      (apply (function call-process)
  110. ;         metamail-program-name
  111. ;         nil
  112. ;         (or buffer t)        ;BUFFER or current buffer
  113. ;         nil            ;don't redisplay
  114. ;         (append metamail-switches (list metafile)))
  115. ;      )))
  116.  
  117. (provide 'metamail)
  118.  
  119. ;;; metamail.el ends here
  120.